package student.aistar.design.singleton.version02;

import student.aistar.design.singleton.version01.Singleton01;

public class Singleton02 {
    //提供一个唯一的对象
    private static Singleton02 instance;

    //构造方法私有化
    private Singleton02(){}

    //提供一个对外访问该类对象的静态方法
    public static Singleton02 getInstance(){
        if(null == instance){
            instance = new Singleton02();
        }
        return instance;
    }
}
class Test{
    public static void main(String[] args) {
        Singleton01 s1 = Singleton01.getInstance();
        Singleton01 s2 = Singleton01.getInstance();
        System.out.println(s1);
        System.out.println(s2);

        System.out.println(s1 == s2);
    }
}